<?php $this->load->module('mobile/index/header', $common);?>

<div class="container">
    <div class="w-item conlist">
        <dl class="fn-clear">
            <dt>线路名称：</dt>
            <dd id="sName"><?php echo $row['line_name']?></dd>
        </dl>
        <dl class="fn-clear">
            <dt>支付金额：</dt>
            <dd><span class="font-orange" >¥<span id="price">0</span></dd>
        </dl>
        <dl class="fn-clear" style="display: none">
            <dt>团期余座：</dt>
            <dd><span class="font-orange " ><span id="seat-num">0</span></dd>
        </dl>
    </div>
    <div class="w-item go-date-head">
        <dl class="in-item fn-clear">
            <dt>发团日期</dt>
            <dd>
                <span class="writeok">
                <select name="date" id="goDate" class="fontorange">
                    <option value="0">请选择团期</option>
                    <?php foreach($go as $k=>$v):?>
                        <option value="<?php echo $v['go_id'];?>"><?php echo $v['go_date'];?></option>
                    <?php endforeach ; ?>
                </select>
                </span>
            </dd>
        </dl>
    </div>

    <div class="w-item">
        <dl class="in-item fn-clear">
            <dt>联系人</dt>
            <dd><input type="text" name="name" placeholder="请填写联系人姓名" value="" class="writeok"></dd>
        </dl>
    </div>
    <div class="w-item marginTop">
        <dl class="in-item fn-clear borderTop">
            <dt>手机号</dt>
            <dd><input type="tel" name="phone" maxlength="11" placeholder="免费接收订单确认短信" value="" class="writeok"></dd>
        </dl>
    </div>

    <input type="hidden" value="0" name="go_id">
    <input type="hidden" value="<?php echo $row['line_id'];?>" name="line_id">
</div>
<div class="col_div">
    <a href="javascript:void(0);" class="btn btn-orange btn_submit" title="提交订单">提交订单</a>
</div>
<?php $this->load->module('mobile/index/footer',$common);?>
<script type="text/javascript">
    function alert_popup(text){
        $.dialog({
            style:'tip',
            width:200,
            closeTime:1000,
            content: '<p style="text-align: center">'+text+'</p>'
        }).open();
    }

    function total_price(){
     var pay = 0 ;
     $('.go-price').each(function(){
         var price = $(this).attr('price');
         var num =   $(this).val();
         pay = price*num + pay  ;
     })
     $('#price').empty().text(pay.toFixed(2));
    }

    $(function(){
        var slid = $("#sliderimg").slider({
            loop: true
        });

        $('.btn_submit').click(function(){

            if($('select[name="date"]').val()== 0){
                alert_popup('请选择团期');
                return false;
            }

            var price_id = new Array();
            var go_num = new Array();
            var totla_num = 0;
            $('.go-price').each(function(i){
                price_id.push($(this).attr('price_id'));
                go_num.push($(this).val());
                totla_num = parseInt( parseInt($(this).val()) + totla_num)  ;
            })

            if(totla_num == '0') {
                alert_popup('出行人数必须>0');
                return false;
            }

            price_id = price_id.join(",");
            go_num = go_num.join(",");


            if($('input[name="name"]').val().length == 0){
                alert_popup('请输入姓名');
                return false;
            }

            if($('input[name="phone"]').val().length == 0){
                alert_popup('请输入手机号');
                return false;
            }else {
                var $val = $("input[name='phone']").val();
                var length = $val.length;
                var status = (length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(14[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test($val));
                if(status==false){
                    alert_popup('请正确填写您的手机号码');
                    return false;
                }
            }



            var line_id = $('input[name="line_id"]').val();
            var go_id = $('input[name="go_id"]').val();
            var name  = $('input[name="name"]').val();
            var phone  = $('input[name="phone"]').val();


            $.post('<?php echo $form_url ;?>',{
                go_id: go_id,
                line_id: line_id,
                price_id: price_id,
                go_num: go_num,
                name: name,
                phone: phone
            },function(data){
                alert_popup(data.info);
                if(data.status=='1')
                {
                    setTimeout(function(){
                        window.location.href='<?php echo site_url('mobile/member/center') ?>';
                    }, 1200);
                }
            },'json')
        })


        $('#goDate').change(function(){
            var goid = $(this).val();
            if(goid=='0'){
                $('.go-box').remove();
                $('#price').empty().text('0');
                return false ;
            }
            $('input[name="go_id"]').val(goid);
            $.post('<?php echo $go_url ;?>',{
                goid: goid
            },function(data){
                if(data.length>0){
                    var html = '<div class="w-item go-box">';
                    for(var i =0;i<data.length;i++){
                        var item = data[i];
                        html += '<dl class="in-item-number fn-clear"><dt>'+item.price_name+'：'+
                                '<span class="font-orange">¥'+item.ws_price+'</span></dt>'+
                                '<dd><span class="btn min_order"></span>'+
                                '<input type="tel" class="ipt-numbers notice go-price" maxlength="3"  '+
                                'price="'+item.ws_price+'" value="1" price_id="'+item.price_id+'" readonly>'+
                                '<span class="btn plus_order"></span>'+
                                '</dd></dl>' ;
                    }
                    html +='</div>';
                    $('.go-box').remove();
                    $('.go-date-head').after(html);
                    total_price();
                }

                var storeNum = 0;
                var $min_order = $('.min_order');
                $min_order.on('click',function(){
                    var obj = $(this).siblings('input');
                    var price =  parseInt(obj.attr('price'));
                    if(obj.val() === ''){
                        return false;
                    }
                    var num = parseInt(obj.val());
                    if(num>0){
                        obj.val(--num);
                    }
                    storeNum = num;
                    total_price();
                })


                var $plus_order = $('.plus_order');
                $plus_order.on('click',function(){
                    var obj = $(this).siblings('input');
                    var price =  parseInt(obj.attr('price'));
                    if(obj.val() === ''){
                        return false;
                    }
                    var num = parseInt(obj.val());
                    obj.val(++num);
                    total_price();
                })
            },'json')
        })
    });
</script>